package cn.tedu.reflection;

import org.junit.Test;

import java.util.Arrays;


/*本类用于测试反射技术*/
public class TestReflect {
    /*单元测试方法:
    * public + void + 没有参数 + 注解@Test
    * Add JUnit4 to classPath
    * 如果成功   import org.junit.Test;*/
    @Test
    public void getClazz() throws ClassNotFoundException {
        Class<?> clazz1 = Class.forName("cn.tedu.reflection.Student");
        Class<?> clazz2 = Student.class;
        Class<?> clazz3 = new Student().getClass();

        System.out.println(clazz1);
        System.out.println(clazz1.getName());
        //通过字节码对象,获取Student类的类名
        System.out.println(clazz2.getSimpleName());
        System.out.println(clazz3.getPackage());
        //通过字节码对象,获取Student类对应的包对象,
        System.out.println(clazz3.getPackage().getName());
    }
    @Test
    public void getStu(){
        System.out.println("中午好");
        Student s1= new Student("张三",3);
        Student s2= new Student("李四",4);
        Student s3= new Student("王五",5);
        Student[] s = {s1,s2,s3};
        System.out.println(Arrays.toString(s));
        //遍历数组
        for(Student stu:s){
            System.out.println(stu);
            stu.eat(3);
            stu.play();
        }
    }
}
